Creating long form datasets in R